import { Window_Base } from "@/windows/Window_Base.js";
import { TextManager } from "@/managers/TextManager.js";
import { ColorExtraction } from "@/utils/ColorExtraction.js";
import { testEquip } from "@/utils/ActorTestTool.js";

export class Window_EquipStatus extends Window_Base {
    constructor(width,height) {
        super(width, height);
        this._actor = null;
        this.refresh();
    }

    destroy(opts){
        super.destroy(opts);
        this._actor=null;
    }

    setActor(actor) {
        if (this._actor != actor) {
            this._actor = actor;
            this.refresh();
        }
    }

    reDraw(equip,slotIndex){
        if (this._actor) {
            this.contents.clear();
            let diff=testEquip(this._actor,equip,slotIndex);
            this.drawActorName(this._actor, 0, 0);
            let lh=this.lineHeight();
            let y=lh;
            for (let i = 2; i < 8; i++) {
                let param=this._actor.param(i);
                this.drawParamName(0, y, i);
                this.resetTextColor();
                this.drawText(param, 140, y, 48,lh,'right');
                if(diff[i]){
                    this.drawRightArrow(188,y);
                    this.changeTextColor(ColorExtraction.paramchangeTextColor(diff[i]));
                    this.drawText(param+diff[i], 222, y, 48,lh, 'right');
                }
                y+=lh;
            }
        }
    }

    drawParamName(x, y, paramId) {
        this.changeTextColor(ColorExtraction.systemColor());
        this.drawText(TextManager.param(paramId), x, y, 120);
    }

    drawRightArrow(x, y) {
        this.changeTextColor(ColorExtraction.systemColor());
        this.drawText('\u2192', x, y, 32,this.lineHeight(), 'center');
    }

    refresh(){
        if (this._actor) {
            this.contents.clear();
            this.drawActorName(this._actor, 0, 0);
            let lh=this.lineHeight();
            let y=lh;
            for (let i = 2; i < 8; i++) {
                let param=this._actor.param(i);
                this.drawParamName(0, y, i);
                this.resetTextColor();
                this.drawText(param, 140, y, 48,lh,'right');
                y+=lh;
            }
        }
    }
}